import { getRoleAuthor } from '@/api/role'
import { ref } from 'vue'
import { RolePermission } from './types'

const useGetPermissionsById = () => {
  const getPermissionsLoading = ref(false)
  const permissions = ref<Array<RolePermission>>([])
  const getPermissions = async (roleId: string) => {
    getPermissionsLoading.value = true
    const res = await getRoleAuthor(roleId)
    permissions.value = res.data.data.rows
    getPermissionsLoading.value = false
  }

  return {
    permissions,
    getPermissionsLoading,
    getPermissions,
  }
}

export default useGetPermissionsById
